package com.ruoyi.auction.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.auction.domain.ShAuction;
import com.ruoyi.auction.service.IShAuctionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拍卖信息管理Controller
 * 
 * @author ruoyi
 * @date 2021-12-29
 */
@Controller
@RequestMapping("/shAuction/auction")
public class ShAuctionController extends BaseController
{
    private String prefix = "shAuction/auction";

    @Autowired
    private IShAuctionService shAuctionService;

    @RequiresPermissions("shAuction:auction:view")
    @GetMapping()
    public String auction()
    {
        return prefix + "/auction";
    }

    /**
     * 查询拍卖信息管理列表
     */
    @RequiresPermissions("shAuction:auction:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShAuction shAuction)
    {
        startPage();
        List<ShAuction> list = shAuctionService.selectShAuctionList(shAuction);
        return getDataTable(list);
    }

    /**
     * 导出拍卖信息管理列表
     */
    @RequiresPermissions("shAuction:auction:export")
    @Log(title = "拍卖信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShAuction shAuction)
    {
        List<ShAuction> list = shAuctionService.selectShAuctionList(shAuction);
        ExcelUtil<ShAuction> util = new ExcelUtil<ShAuction>(ShAuction.class);
        return util.exportExcel(list, "拍卖信息管理数据");
    }

    /**
     * 新增拍卖信息管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存拍卖信息管理
     */
    @RequiresPermissions("shAuction:auction:add")
    @Log(title = "拍卖信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShAuction shAuction)
    {
        return toAjax(shAuctionService.insertShAuction(shAuction));
    }

    /**
     * 修改拍卖信息管理
     */
    @GetMapping("/edit/{aid}")
    public String edit(@PathVariable("aid") Long aid, ModelMap mmap)
    {
        ShAuction shAuction = shAuctionService.selectShAuctionById(aid);
        mmap.put("shAuction", shAuction);
        return prefix + "/edit";
    }

    /**
     * 修改保存拍卖信息管理
     */
    @RequiresPermissions("shAuction:auction:edit")
    @Log(title = "拍卖信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShAuction shAuction)
    {
        return toAjax(shAuctionService.updateShAuction(shAuction));
    }

    /**
     * 删除拍卖信息管理
     */
    @RequiresPermissions("shAuction:auction:remove")
    @Log(title = "拍卖信息管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shAuctionService.deleteShAuctionByIds(ids));
    }
}
